/**
 * 匠言知识付费v2.0.0
 * Author: 山西匠言网络科技有限公司
 * 这不是一个免费软件，它受限于许可条款，你可以访问https://www.zsfzxkc.cn/获取更多详细信息。
 * This is not a free software, it under the license terms, you can visit https://www.zsffzxkc.cn/ get more details.
 */
<template>
	<view class="container">
		
		
		<view class="header">
			<button type="primary">筛选</button>
			<view class="uni-list">
				<picker class="picker" @change="bindPickerChange" :value="index" :range="array">
					<view class="uni-input">{{array[index]}}<image src="../static/xiangxia11.png" mode="aspectFit"></image></view>
					
				</picker>
			</view>
		</view>
		
		
		<wyb-table height="auto" ref="table" first-line-fixed="true" :headers="headers" :contents="contents" :url-col="urlCol" />
		
		   <zhini-pagination :totalPage="14" :currentPage.sync="currentPage"  @pageNum="getNum" ></zhini-pagination>
	</view>
</template>

<script>
	
	import wybTable from '../components/wyb-table/wyb-table.vue'
	import ZhiniPagination from '../components/zhini-pagination/zhini-pagination.vue'
	import { checkUserinfo } from '@/request/checkUserinfo'
	import { postAgentJhm } from '@/request/agent.js'
	export default {
		components: {
			wybTable,
			ZhiniPagination
		},
		data() {
			return {
				array: ['是否激活', '已激活', '未激活'],
				page: 1,
				currentPage: 3,
				index: 0,
				headers: [
					{label: '优惠码',key: 'num'},
					{label: '序号',key: 'id'}, 
					{label: '商品类型',key: 'goodstype'},
					{label: '商品ID',key: 'goodsid'}, 
					{label: '有效期(天)',key: 'days'},
					{label: '价值',key: 'price'},
					{label: '复制',key: 'link'}],
				contents: [],
				urlCol: [
					{type: 'route', key: 'url'},
					{type: 'http', key: 'link'}]
			}
		},
		onShareAppMessage(res) {
			let path = getCurrentPages()
			let path_share = path[0].$page.fullPath
			let path_title = path[0].data.title
			let userinfo = uni.getStorageSync('userinfo')
			let base_set = uni.getStorageSync('base_set')
			if(userinfo.uid=='' || !userinfo.uid){
				uni.navigateTo({
					url:'../login/login'
				})
				return {
					title: '请先登录后再分享给好友',
					path: ''
				}
			}else{
				if (res.from === 'button') {
					
				}
				return {
					title: base_set.title,
					path: `${path_share}?pid=${userinfo.uid}`
				}
			}
		},
		onShow() {
			checkUserinfo()
			this.postAgentJhm(0)
		},
		methods: {
			bindPickerChange (e) {
				console.log('picker发送选择改变，携带值为', e.target.value)
				this.index = e.target.value
				if(this.index == 1) {
					this.postAgentJhm(1)
				} else {
					this.postAgentJhm(0)
				}
			},
			postAgentJhm(e) {
				let userinfo=uni.getStorageSync('userinfo')
				postAgentJhm({uid: userinfo.uid, is_jh: e, jhmtype: 'yhm'}).then(res => {
					console.log(res.data)
					if(res.data.code==0){
						this.contents = res.data.data
						res.data.data.forEach((item,index) => {
							this.contents[index].goodsname = item.goodsinfo.name
						})
					}
				})
			}
		}
	}
</script>

<style lang="less" scoped>

.header {
	margin: 30upx 0 30upx 30upx;
	display: flex;
	align-items: center;
	button {
		margin: 0;
		height: 60upx;
		line-height: 60upx;
		font-size: 30upx;
	}
	.uni-list {
		height: 60upx;
		line-height: 60upx;
		padding: 0 20upx;
		margin-left: 30upx;
		border: 2upx solid #ddd;
		border-radius: 10upx;
		.picker {
			.uni-input {
				display: flex;
				align-items: center;
				image {
					width: 24upx;
					height: 14upx;
					margin-left: 10upx;
				}
			}
		}
	}
}


</style>
